Repository navigation
feat(core): Inject trace context into outgoing MCP server messages - #26311
sentry-junior[bot] wants to merge 6 commits into
Conversation
740f240 to
fa2456a
Compare
Optional E2E testsSome optional checks were not successful. They do not block the merge. 4 not successful, 55 successful. See the run.
Successful checks
|
size-limit report 📦Compared: c2fb482 (PR test merge using develop at d90ea11) Against: 88cc648 (develop) · base run #66002
|
fa2456a to
07b9d1c
Compare
b665dda to
d5efefb
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d5efefb. Configure here.
Co-Authored-By: Francesco Gringl-Novy <francesco.novy@sentry.io>
65c51e6 to
a276df9
Compare
The trace injection integration test now also sends an elicitation request from the tool handler and asserts that the client continues the trace with the tools/call span as parent.

Stacked on #26308.
Why: #26308 continues traces from
params._metaon incoming messages. This adds the other direction. Server-to-client requests (sampling, elicitation, roots, ping) and notifications (progress, logging, ...) now carrysentry-traceandbaggageinparams._meta, plustraceparentwhenpropagateTraceparentis enabled (the same opt-in as for HTTP). That lets a client link its handling back to the tool call that triggered it. Requests are parented to the active span, which inside a handler is thetools/callspan. Notifications are parented to their ownmcp.notification.server_to_clientspan.Messages that already carry
sentry-traceortraceparent, or whose_metaisn't an object, go through untouched, so we never overwrite context someone else set. The message is copied rather than mutated, because callers can reuse the object. Responses are left alone, since the spec only defines propagation for requests and notifications.How to review: Start with
injectMcpTraceContextintracePropagation.ts, then its two call sites inwrapTransportSend. The node integration test has an uninstrumented client continue the trace from what it received, which proves_metasurvives the real MCP SDK. The mock clients intestUtils.tsnow havegetTransport, becausegetTraceDatareads it throughisEnabled().Unsure about: Out of scope: MCP client instrumentation, which would inject on client-to-server requests.
via Francesco Gringl-Novy.
--
View Session [Sentry]